package com.example.demo;

import android.os.Binder;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by yls on 2018/12/17.
 */

public class MyBinder extends Binder{

     public int add(int a,int b){
         return a+b;
     }

     public String getTime(){
         Date date = new Date();
         SimpleDateFormat format = new SimpleDateFormat("yyyy:MM:dd hh:mm:ss");
         return format.format(date);
     }

     //单词逆序
    public String reverse(String str) {
        // String 截取方法——完全逆序
       if (str==null||str.length()<=1){
           return str;
       }
       String rs = "";
       for (int i=str.length()-1;i>=0;i--){
           rs += str.substring(i,i+1);
       }

       //利用空格-变成句子中的单词逆序
        StringBuffer strBuilder = new StringBuffer(rs.length() + 1);
        String[] words = rs.split(" ");
        for (int i = words.length-1;i>=0;i--){
            strBuilder.append(words[i]).append(' ');
        }
        strBuilder.setLength(strBuilder.length()-1);
        return strBuilder.toString();
    }

}
